package com.shenjian.workbench.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shenjian.workbench.dao.ActivityDao;
import com.shenjian.workbench.entity.Activity;
import com.shenjian.workbench.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * (Activity)表服务实现类
 *
 * @author makejava
 * @since 2022-07-02 16:45:47
 */
@Service
public class ActivityServiceImpl implements ActivityService {
    @Autowired
    private ActivityDao activityDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Activity queryById(String id) {
        return this.activityDao.selectById(id);
    }

    /**
     * 条件分页查询
     *
     * @param activity 筛选条件
     * @param pageNumber 当前页数
     * @param pageSize 每页条数
     * @return 查询结果
     */
    @Override
    public Map<String, Object> listPage(Integer pageNumber,Integer pageSize,Activity activity) {
        PageHelper.startPage(pageNumber, pageSize);
        PageInfo pageInfo = new PageInfo(activityDao.select(activity));
        Map<String, Object> map = new HashMap<>();
        map.put("list", pageInfo.getList());
        map.put("total", pageInfo.getTotal());
        return map;
    }

    /**
     * 新增数据
     *
     * @param activity 实例对象
     * @return 实例对象
     */
    @Override
    public boolean insert(Activity activity) {
        return activityDao.insert(activity)>0;
    }

    /**
     * 修改数据
     *
     * @param activity 实例对象
     * @return 实例对象
     */
    @Override
    public boolean update(Activity activity) {
        return activityDao.update(activity)>0;
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String id) {
        return this.activityDao.deleteById(id) > 0;
    }

    /**
     * 通过主键删除数据
     *
     * @param ids 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteBatch(String[] ids) {
        return this.activityDao.deleteBatch(ids) > 0;
    }


}
